home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / CGI.TRM < prev    next >
Text File  |  1992-03-25  |  5KB  |  232 lines

  1. /*
  2.  * $Id: cgi.trm,v 3.26 92/03/24 22:34:47 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - cgi.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992 Ronald Florence
  8.  *
  9.  * Permission is hereby granted for unlimited non-commercial
  10.  * use of this code, on condition that the copyright
  11.  * notices are left intact and any modifications to the source
  12.  * code are noted as such.  No warranty of any kind is implied
  13.  * or granted for this material.
  14.  *
  15.  * This file is included by ../term.c.
  16.  *
  17.  * This terminal driver supports SCO CGI drivers
  18.  *
  19.  * AUTHOR
  20.  *   Ronald Florence <ron@mlfarm.com>
  21.  */
  22.  
  23. #ifdef VGA_MONO
  24. static short rgb[16][3] = {
  25.   0,    0,      0,      /* Black        */
  26.   1000,    1000,    1000,    /* White    */
  27.   800,    800,    0,    /* Red        */
  28.   0,    600,    0,    /* Green    */
  29.   0,    800,    800,    /* Blue        */
  30.   1000,    1000,    400,    /* Yellow    */
  31.   0,    600,    600,    /* Cyan        */
  32.   600,    600,    600,    /* Magenta    */
  33.   800,    800,    0,    /* Brown    */
  34.   600,    600,    600,    /* Lt. Grey    */
  35.   400,    600,    400,    /* Dark Grey    */
  36.   400,    600,    1000,    /* Lt. Blue    */
  37.   400,    1000,    400,    /* Lt Green    */
  38.   400,    1000,    1000,    /* Lt Cyan    */
  39.   1000,    600,    400,    /* Lt Red    */
  40.   600,    600,    1000    /* Lt Magenta    */
  41. };
  42. #endif
  43.  
  44. #define CGI_XMAX    32767
  45. #define CGI_YMAX    32767
  46. #define CGI_VTIC    (CGI_YMAX / 75)
  47. #define CGI_HTIC    term_tbl[term].h_tic
  48. #define CGI_VCHAR    term_tbl[term].v_char
  49. #define CGI_HCHAR    term_tbl[term].h_char
  50. #define CRT        (gout[45] == 0)
  51. #define CGICOLORS    gout[13]
  52. #define CGILINES    gout[6]
  53. #define CGIROTATES    gout[36]
  54. #define CGITEXTALIGN    gout[48]
  55.  
  56. static short gout[66];
  57. static short cgidev;
  58. static short vect[4];
  59. static short gin[19] = {
  60.  0,    /* default aspect ratio */
  61.  1,    /* solid line */
  62.  1,    /* line color */
  63.  1,    /* marker type . */
  64.  1,    /* marker color */
  65.  1,    /* graphics text font */
  66.  1,    /* graphics text color */
  67.  0,    /* fill interior style */
  68.  0,    /* fill style index */
  69.  1,    /* fill color index */
  70.  1     /* prompt for paper changes */
  71.  };
  72.  
  73. char    *cgidriver, *getenv();
  74.  
  75.  
  76. CGI_init()
  77. {
  78.   if (getenv(cgidriver = "CGIDISP") == NULL)
  79.     HCGI_init();
  80. }
  81.  
  82.  
  83. HCGI_init()
  84. {
  85.   if (getenv(cgidriver = "CGIPRNT") == NULL)
  86.     int_error("no CGI driver", NO_CARET);
  87. }
  88.  
  89.  
  90. CGI_graphics()
  91. {
  92.   int    i, aspect;
  93.   char *s;
  94.   short font_cap[9];
  95.   char    err_str[80];
  96.  
  97.   if ( (s=getenv("ASPECT")) != NULL && (aspect=atoi(s)) >= 0 && aspect <= 3 )
  98.     gin[0] = aspect;
  99.   for (i = 0; cgidriver[i]; i++) 
  100.     gin[11+i] = cgidriver[i];
  101.   gin[18] = ' ';
  102.  
  103.   if (v_opnwk(gin, &cgidev, gout) < 0) 
  104.     {
  105.       sprintf(err_str, "CGI error %d opening %s", -vq_error(), cgidriver);
  106.       int_error(err_str, NO_CARET);
  107.     }
  108.   vqt_representation(cgidev, 9, font_cap);
  109.   CGI_VCHAR = font_cap[8] * 3 / 2;
  110.   CGI_HCHAR = font_cap[7];
  111.   CGI_HTIC = CGI_VTIC * ((double) gout[1] / (double) gout[4]) / 
  112.             ((double) gout[0] / (double) gout[3]);
  113. #ifdef VGA_MONO
  114.   if (CGICOLORS > 2)
  115.     vsc_table(cgidev, 0, CGICOLORS, rgb);
  116. #endif
  117. }
  118.  
  119.  
  120. CGI_text()
  121. {
  122.   if (CRT)  
  123.     {
  124.       short ptin[2];
  125.       char  strin[2];
  126.       
  127.       ptin[0] = 0;
  128.       ptin[1] = 0;
  129.       vrq_string(cgidev, 1, 0, ptin, strin);
  130.     }
  131.   v_clswk(cgidev);
  132. }
  133.  
  134.  
  135. CGI_reset()
  136. {
  137. }
  138.  
  139.  
  140. CGI_move(x, y)
  141.      int x, y;
  142. {
  143.   vect[0] = x;
  144.   vect[1] = y;
  145. }
  146.  
  147. CGI_vector(x, y)
  148.      int x, y;
  149. {
  150.   vect[2] = x;
  151.   vect[3] = y;
  152.   v_pline(cgidev, 2, vect);
  153.   vect[0] = x;
  154.   vect[1] = y;
  155. }
  156.  
  157.  
  158. CGI_linetype(linetype)
  159.      int linetype;
  160. {
  161.   short lcolor;
  162.  
  163.   if (CGICOLORS > 2) 
  164.     {
  165.       lcolor = (linetype + 2) % CGICOLORS + 1;
  166.       vsl_color(cgidev, lcolor);
  167.       vsm_color(cgidev, lcolor);
  168.     }
  169.   vsl_type(cgidev, (linetype < 1) ? 1 : (linetype % CGILINES) + 1);
  170. }
  171.  
  172.  
  173. CGI_put_text(x, y, str)
  174. int x, y;
  175. char *str;
  176. {
  177.   v_gtext(cgidev, (short) x, (short) y, str);
  178. }
  179.  
  180.  
  181. CGI_text_angle(ang)
  182. int    ang;
  183. {
  184.   if (!CGIROTATES)
  185.     return FALSE;
  186.                 /* angles are 1/10 degree ccw */
  187.   vst_rotation(cgidev, (ang) ? 900 : 0);
  188.   return TRUE;
  189. }
  190.  
  191.  
  192. CGI_justify_text(mode)
  193. enum JUSTIFY mode;
  194. {
  195.   short hor_in, hor_out, vert_out;
  196.  
  197.   if (!CGITEXTALIGN)
  198.     return FALSE;
  199.  
  200.   switch (mode)
  201.     {
  202.     case LEFT:   hor_in = 0; break;
  203.     case CENTRE: hor_in = 1; break;
  204.     case RIGHT:  hor_in = 2; break;
  205.     }
  206.   vst_alignment(cgidev, hor_in, 1, &hor_out, &vert_out); 
  207.   return TRUE;
  208. }
  209.  
  210.  
  211. #define POINT_TYPES 6
  212.  
  213. CGI_point(x,y,num)
  214.      int x, y, num;
  215. {
  216.   short  point[2];
  217.   static short cgimarker[POINT_TYPES] = {1, 2, 6, 4, 5, 3};
  218.                           /* .  +  <> [] X  * */
  219.   if (num < 0)
  220.     {
  221.       CGI_move(x, y);
  222.       CGI_vector(x, y);
  223.     }
  224.   else
  225.     {
  226.       vsm_type(cgidev, cgimarker[num % POINT_TYPES]);
  227.       point[0] = x;
  228.       point[1] = y;
  229.       v_pmarker(cgidev, 1, point);
  230.     }
  231. }
  232.